package com.intellagric.service.iftmonitor.Impl.ift_channel_reporting;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.IftChannelReportingMapper;
import com.intellagric.pojo.IftChannelReporting;
import com.intellagric.pojo.IftChannelReportingExample;
import com.intellagric.service.iftmonitor.ift_channel_reporting.ChannelReportingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 通道报告信息服务实现
 */
@Service
public class ChannelReportingServiceImpl implements ChannelReportingService {

    @Autowired
    private IftChannelReportingMapper channelReportingMapper;

    /**
     * 添加通道报告信息
     * @param channelReporting
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addChannelReporting(IftChannelReporting channelReporting) {
        if (channelReportingMapper.insertSelective(channelReporting) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除通道报告信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteChannelReporting(String id) {
        if (channelReportingMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改通道报告信息
     * @param channelReporting
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editChannelReporting(IftChannelReporting channelReporting) {
        if (channelReportingMapper.updateByPrimaryKey(channelReporting) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询通道报告信息
     * @param id
     * @return IftChannelReporting
     */
    @Override
    public IftChannelReporting getChannelReportingById(String id) {
        return channelReportingMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询通道报告信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getChannelReportingList() {
        IftChannelReportingExample channelReportingExample = new IftChannelReportingExample();
        channelReportingExample.createCriteria().andIdIsNotNull();
        List<IftChannelReporting> channelReportingList = channelReportingMapper.selectByExample(channelReportingExample);
        return LayuiDataGridResult.success().add(channelReportingList,channelReportingList.size());
    }

    /**
     * 分页查询通道报告信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getChannelReportingPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftChannelReportingExample channelReportingExample = new IftChannelReportingExample();
        channelReportingExample.createCriteria().andIdIsNotNull();
        List<IftChannelReporting> channelReportingList = channelReportingMapper.selectByExample(channelReportingExample);
        LayuiDataGridResult result = new LayuiDataGridResult();
        result.setData(channelReportingList);
        return result;
    }
}
